//
//  PackageDetailCell.m
//  DingDongXiChe
//
//  Created by wtjr on 2017/11/27.
//  Copyright © 2017年 xieyingze. All rights reserved.
//

#import "PackageDetailCell.h"
#import "CustomReuseCellView.h"

@interface PackageDetailCell()

@property (nonatomic, strong) UIView *mainView;
/**
 套餐名称
 */
@property (nonatomic, strong) CustomReuseCellView *serviceNameView;
/**
 套餐服务时长
 */
@property (nonatomic, strong) CustomReuseCellView *serviceDurationView;
/**
 套餐服务价格
 */
@property (nonatomic, strong) CustomReuseCellView *servicePriceView;

@end

@implementation PackageDetailCell

+ (instancetype)cellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath {
    static NSString *cellId = @"PackageDetailCell";
    PackageDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (cell == nil) {
        cell = [[PackageDetailCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
    }
    return cell;
}

#pragma mark - Init

- (void)initSubView {
    [self addSubview:self.mainView];
    [self.mainView addSubview:self.serviceNameView];
    [self.mainView addSubview:self.serviceDurationView];
    [self.mainView addSubview:self.servicePriceView];
}

- (void)autoLayoutSubviews {
    [self.mainView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(@0);
    }];
    [self.serviceNameView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(@0);
        make.top.equalTo(@0);
        make.height.equalTo(@(kUI_CellHeight));
    }];
    [self.serviceDurationView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(@0);
        make.top.equalTo(self.serviceNameView.mas_bottom);
        make.height.equalTo(@(kUI_CellHeight));
    }];
    [self.servicePriceView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(@0);
        make.top.equalTo(self.serviceDurationView.mas_bottom);
        make.height.equalTo(@(kUI_CellHeight));
    }];
}

#pragma mark - Setter

- (void)setViewModel:(PackageViewModel *)viewModel {
    _viewModel = viewModel;
    self.serviceNameView.value = viewModel.currentPackageModel.package_name;
    self.servicePriceView.value = [NSString stringWithFormat:@"%.2f元",viewModel.currentPackageModel.package_price];
    self.serviceDurationView.value = [NSString stringWithFormat:@"%ldmm",(long)viewModel.currentPackageModel.package_duration];
}

#pragma mark - Getter

- (UIView *)mainView {
    if (!_mainView) {
        _mainView = [UIView new];
        _mainView.backgroundColor = kCOLOR_white;
    }
    return _mainView;
}

- (CustomReuseCellView *)serviceNameView {
    if (!_serviceNameView) {
        _serviceNameView = [CustomReuseCellView new];
        _serviceNameView.iconName = @"dd_package_package";
        _serviceNameView.title = @"服务套餐";
        _serviceNameView.value = @"套餐";
    }
    return _serviceNameView;
}

- (CustomReuseCellView *)serviceDurationView {
    if (!_serviceDurationView) {
        _serviceDurationView = [CustomReuseCellView new];
        _serviceDurationView.iconName = @"dd_package_duration";
        _serviceDurationView.title = @"服务时长";
        _serviceDurationView.value = @"60";
    }
    return _serviceDurationView;
}

- (CustomReuseCellView *)servicePriceView {
    if (!_servicePriceView) {
        _servicePriceView = [CustomReuseCellView new];
        _servicePriceView.iconName = @"dd_package_price";
        _servicePriceView.title = @"套餐价格";
        _servicePriceView.value = @"58";
    }
    return _servicePriceView;
}
@end
